package lanQiaoBei.动态规划.线性dp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
//https://blog.csdn.net/qq_45654671/article/details/112448456
public class 数字三角形 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       final static int N=510;
       static int f[][]=new int[N][N],a[][]=new int[N][N],n;
       
       public static void main(String[] ss) throws  IOException {
		      n=Integer.parseInt(br.readLine());
		      for(int i=1;i<=n;i++){
		    	  ss=br.readLine().split(" ");
		    	  for(int j=1;j<=i;j++)
		    		  a[i][j]=Integer.parseInt(ss[j-1]);
		      }
		      for(int i=0;i<=n;i++)
		    	  Arrays.fill(f[i],-0x3f3f3f3f);
		      f[1][1]=a[1][1];
		      for(int i=2;i<=n;i++)
		    	  for(int j=1;j<=i;j++)
		    		  f[i][j]=Math.max(f[i-1][j-1], f[i-1][j])+a[i][j];
		      int res=-0x3f3f3f3f;
		      for(int j=1;j<=n;j++){
		    	  res=Math.max(f[n][j], res);
		      }
		      System.out.print(res);
	}
}
